#ifndef POLYGONITEM_H
#define POLYGONITEM_H

#include <QGraphicsPolygonItem>
#include <QList>
#include <QMenu>
#include <QAction>
class LabelScene;
class VertexItem;
class PolygonItem : public QObject, public QGraphicsPolygonItem
{
    Q_OBJECT
public:
    QList<VertexItem* > myVertexes;
    enum { Type = UserType + 4 };
    int type() const override { return Type; }
    enum PolygonType { Polygon, Rectangle };
    PolygonItem(LabelScene* scene, QGraphicsItem *parent = nullptr);
    QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;

    QString text() const {return myText;};
    void setText(const QString &text) {myText = text;}
    void setScene(LabelScene* scene) {myScene = scene;}
    LabelScene* scene() {return myScene;}
    void addVertex(VertexItem* vertex, bool beforeIsMoving, bool AfterIsMoving);
    QPolygonF polygon() { return myPolygon; }
    void setPolygon(QPolygonF polygon) {myPolygon = polygon; QGraphicsPolygonItem::setPolygon(polygon);}



    QList<VertexItem* > vertexes() { return myVertexes; }
    void appendVertexToRectangle(VertexItem* vertexItem) {myVertexes.append(vertexItem);}
    void addRectangle(VertexItem *vertex, QPointF pos1, QPointF pos2);
    void setRectangle() { isRectangle = 1;}
    bool getIsRectangle() { return isRectangle;}
signals:
    void requestDelete(PolygonItem *item);
    void requestModify(PolygonItem *item);

protected:
    void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override;
private:
    bool isRectangle = 0;

    QPolygonF myPolygon;
    LabelScene* myScene;
    QString myText;
};

#endif // POLYGONITEM_H
